﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace _1vs100
{
    public class Question
    {
        String[,] gameQuestions;
        int row;

        public Question()
        {
            gameQuestions = new String[13, 5]; 
            row = 0;
        }

        public String[,] Questions
        {
            get { return gameQuestions; }
            set { gameQuestions = value; }
        }

        public void fillQuestion(String diff)
        {
            String file = "";
            int r = 0, c = 0;

            if (diff.Equals("General"))
            {
                file = "QuestionsFile.txt";
            }
            else if (diff.Equals("Movies"))
            {
                file = "QuestionsFile1.txt";
            }
            else
            {
                file = "QuestionsFile2.txt";
            }

            try
            {
                using (StreamReader reader = new StreamReader(file))
                {
                    String line;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (c == 5)
                        {
                            r++;
                            c = 0;
                        }
                        gameQuestions[r, c] = line;
                        c++;
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error reading file", e);
            }

        }

        public String getQuestion(int r, int c)
        {
            return gameQuestions[r, c];
        }

        public String getNextQuestion()
        {
            try
            {
                return gameQuestions[row, 0];
            }
            catch (Exception e)
            {
                throw new Exception("Ran out of questions", e);
            }
        }

        public String getCurrentAnswer()
        {
            return gameQuestions[row, 4]; 
        }

        public String[] getCurrentChoices()
        {
            String[] choices = new String[3];
            for (int i = 0; i < 3; i++)
            {
                choices[i] = gameQuestions[row, i + 1];
            }
            return choices;
        }

        public void incrQ()
        {
            row++;
        }
    }
}
